<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>模板导入</title>
    <#include "/pubHeadStyle.html">
</head>
<body>
<form class="layui-form"  style="padding: 10px">
    <table class="table-detail ">
        <tr >
            <th style="width: 32%; ">导入文件:</th>
            <td>
                <button class="layui-btn layui-btn-sm" type="button" name="xmlFile" id="xmlFile" style="margin-top: 4px">
                    <i class="layui-icon"></i>
                    上传文件
                </button>
            </td>

        </tr>
        <tr>
            <th>是否删除同用途的模板:</th>
            <td class="layui-input-block" >
                <input type="checkbox" name="clearAll" lay-skin="primary" id="clearAll" checked>
            </td>
        </tr>
        <tr>
            <th >是否设置为默认:</th>
            <td class="layui-input-block" >
                <input type="checkbox" name="setDefault" id="setDefault" lay-skin="primary" checked>
            </td>
        </tr>
    </table>

    <div class="layui-btn-container layui-footer" style="position: absolute;left:37%;bottom:0">
        <button type="button"  lay-submit class="layui-btn layui-btn-sm" id="importButton">导入</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" id="return">取消</button>
    </div>
</form>

<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','element', 'upload', 'jquery','form','setter','layer'], function () {
        var element = layui.element;
        var upload = layui.upload;
        var $ = layui.$;
        var setter = layui.setter;
        var layer = layui.layer;
        var form = layui.form;

        var index = parent.layer.getFrameIndex(window.name);
        $('#return').click(function () {
            parent.layer.close(index);
        });

        //指定允许上传的文件类型
        upload.render({
            elem: '#xmlFile'
            , url: serverPath.workflowPath + setter.workflowLinkPath + 'sysTemplate/importXml'
            , accept: 'file'
            , multiple: true
            , exts:'xml'
            , auto: false //选择文件后不自动上传
            ,bindAction: '#importButton' //指向一个按钮触发上传
            , before: function (obj) {
                this.data ={"clearAll":$("input[name='clearAll']").is(':checked')? 1: 0,
                            "setDefault":$("input[name='setDefault']").is(':checked')? 1: 0};
            }
            ,done: function(res){
                if(res.code==1){
                    if(res.data){
                        parent.layer.alert(res.data, {icon: 2, time: 2500});
                    }else{
                        paretn.layer.alert(res.msg , {icon: 2, time: 2500});
                    }
                } else {
                    layer.alert(res.msg, {icon: 1, time: 2500} ,function (index1) {
                        layer.close(index1);
                        parent.layui.table.reload('noteTemplate', {
                            page: {curr: 1}
                        });
                        parent.layui.totalFilter.init('noteTemplate');
                        parent.layer.close(index);
                    });
                }
            }
        });

    })
</script>
</body>
</html>